package com.ray.quartz.common;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.ray.api.service.UcenterApiService;
import com.ray.auth.system.table.entity.App;
import com.ray.auth.system.table.entity.Notice;
import com.zjhc.flyhong.common.function.operator.LoginUser;
import com.zjhc.flyhong.common.web.Result;
import com.zjhc.web.controller.WebController;

/**
 * <h1>通用树 控制器</h1>
 * 
 * @创建人 ray
 * @创建时间 2017-06-12
 * @版本 1.0
 * @重要修改备注
 * 
 */
@Controller
@RequestMapping("/common")
public class CommonController extends WebController{



	@Autowired
	UcenterApiService ucenterApiService;

	/**
	 * 我的页面
	 * @return
	 */
	@RequestMapping(value = "my")
	public ModelAndView my(String id, HttpServletRequest request, HttpServletResponse respose,
			ModelAndView modelAndView){
	  LoginUser user = getLoginUser();
	  List<App> apps = ucenterApiService.queryApp();
	  modelAndView.addObject("apps", apps);
	  modelAndView.addObject("record", user.getExtendUser());
	  modelAndView.setViewName("my");
	  return modelAndView;
	}
	
	
	/**
	 * 工作详情
	 * @return
	 */
	@RequestMapping(value = "workDetail")
	public ModelAndView workDetail(String id, HttpServletRequest request, HttpServletResponse respose,
			ModelAndView modelAndView){
	  LoginUser user = getLoginUser();
	//  Work record =  workService.queryWork(id, user);
	 // modelAndView.addObject("record", record);
	  modelAndView.setViewName("common/work/detail");
	  return modelAndView;
	}
	
	/**
	 * 通知详情
	 * @return
	 */
	@RequestMapping(value = "noticeDetail")
	public ModelAndView noticeDetail(String id, HttpServletRequest request, HttpServletResponse respose,
			ModelAndView modelAndView){
	  LoginUser user = getLoginUser();
	 // Notice record =  noticeService.queryNotice(id, user);
	//  modelAndView.addObject("record", record);
	  modelAndView.setViewName("common/notice/detail");
	  return modelAndView;
	}
	
	/**
	 * 通知详情
	 * @return
	 */
	@RequestMapping(value = "noticeDetailWindow")
	public ModelAndView noticeDetailWindow(String id, HttpServletRequest request, HttpServletResponse respose,
			ModelAndView modelAndView){
	  LoginUser user = getLoginUser();
	//  Notice record =  noticeService.queryNotice(id, user);
	//  modelAndView.addObject("record", record);
	  modelAndView.setViewName("common/notice/window");
	  return modelAndView;
	}
	
	/**
	 * 最新通知
	 * @return
	 */
	@RequestMapping(value = "windowNotice")
	@ResponseBody
	public ResponseEntity<Result<Object>> windowNotice(HttpServletRequest request, HttpServletResponse respose){
		Result<Object> result = null;
		LoginUser user = getLoginUser();
		Notice notice = null; //noticeService.queryFirstWindowNotice(user);
		if(notice == null){
			result = new Result<Object>(-1, "无弹窗通知");
		}else{
			result = new Result<Object>(0, "",notice);
		}
		return doResult(result);
	}
	
}
